import { createStore } from "vuex";
import { RootState } from "./interface";
import getters from "./getters";

// 使用Webpack的require.context导入所有模块
const modulesContext = require.context("./modules", false, /\.ts$/);

export const modules = modulesContext.keys().reduce((modules, modulePath) => {
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, "$1");
  const value = modulesContext(modulePath);
  modules[moduleName] = value.default;
  return modules;
}, {} as Record<string, any>);

// 创建store
const store = createStore<RootState>({
  modules,
  getters,
});

export default store;
